package cn.jiyun.function.service.impl;

import cn.jiyun.function.mapper.CarMapper;
import cn.jiyun.function.mapper.DriverMapper;
import cn.jiyun.function.mapper.OrdersMapper;
import cn.jiyun.function.service.OrdersService;
import cn.jiyun.pojo.function.Car;
import cn.jiyun.pojo.function.Driver;
import cn.jiyun.pojo.Orders;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrdersServiceImpl  implements OrdersService {
    @Autowired
    OrdersMapper orderMapper;
    @Autowired
    DriverMapper driverMapper;
    @Autowired
    CarMapper carMapper;

    @Override
    public PageInfo<Orders> findPage(Integer pageNum, Integer pageSize, Orders orders1) {
        Page<Orders> page = PageHelper.startPage(pageNum, pageSize);
        List<Orders> list = orderMapper.findPage(page, orders1);
        List<Driver> driverList = driverMapper.findList();
        List<Car> carList = carMapper.findList();
        for (Orders orders : list) {
            for (Driver user : driverList) {
                if (orders.getUserId() != null && orders.getUserId().equals(user.getId())) {
                    orders.setUserName(user.getUserName());
                    orders.setUserPhone(user.getUserPhone());
                }
            }
            for (Driver driver : driverList) {
                if (orders.getDriverId() != null && orders.getDriverId().equals(driver.getId())) {
                    orders.setDriverName(driver.getUserName());
                    orders.setDriverPhone(driver.getUserPhone());
                }
            }
        }
        for (Orders orders : list) {
            if (orders.getDriverName() != null) {
                for (Car car : carList) {
                    if (orders.getDriverId().equals(car.getDid())) {
                        orders.setCarName(car.getLicencePlate());
                    }
                }
            }
        }
        return new PageInfo<>(list);
    }

    @Override
    public Orders findxq(Integer id) {
        return orderMapper.findxq(id);
    }
}
